
;; Get galactic params
defsysv, '!MW', exists = exists
IF ~ exists THEN galactic_params 
d = dindgen(!MW.NBINS)*!MW.BINSIZE + !MW.BINSTART
R0 = !MW.R0

restore,'./emaf_paper/save_files/morph_distances.sav',/ver
restore,'./emaf_paper/bgps_emaf.sav',/ver
n = n_elements(emaf)

;; Restrict consideration to "well-constrained" sources...
cind  = where(constr_ml,n)
duse   = duse[cind,*]
dbar  = dbar[cind,*]
emaf  = emaf[cind]
pchoo = pchoo[cind]


;;==========================================================================
;; Set up the plotting environment   
myps,'./emaf_paper/plots/emaf_galpos.eps',ct=0,xsize=5,ysize=6,/cmyk

xtit='Galactocentric Distance [kpc]'
ytit='Galactocentric Distance [kpc]'

;;FOR rotc=0b, 3b, 2b DO BEGIN

   cgLoadct,40,/silent,/reverse
   symsize = (alog10(emaf.s40)+1.2)/1.9*1.5
   color   = fix(round(emaf.c/0.5*254.)<254.)>0

   Plot,[-9.0,1.0],[-9,7],/nodata,xtit=xtit,$
        ytit=ytit,ytickformat=ytf,/xst,/yst,xticks=10,xticklen=0.005,$
        tit=rtit,charsize=1.2,/isotropic,xtickformat='funky'
   
   ;; Solar Circle and Tangent Circles
   ells = findgen(1001)/1.e3*180.
   scl = findgen(1001)/1.e3*360.
   xells = -(R0/1.d3 * cos(ells*!dtor)) *  sin(ells * !dtor)
   yells = + (R0/1.d3 * cos(ells*!dtor)) * cos(ells * !dtor) - R0/1.d3
   xsc   = -R0/1.d3 * cos(scl * !dtor)
   ysc   = -R0/1.d3 * sin(scl * !dtor)
   xbar  = -3.5 * cos(scl * !dtor)
   ybar  = -3.5 * sin(scl * !dtor)
   cgOplot,xells,yells,linestyle=1,color='BLK6',thick=1
   cgOplot,xsc,ysc,linestyle=1,color='BLK6',thick=1
   cgOplot,xbar,ybar,linestyle=5,color='BLK6',thick=1

   ;; l=30 line (through end of the Bar)
   cgPlots,0,-R0/1.d3
   cgPlots,-R0/1.d3*cos(30*!dtor),R0/1.d3*sin(30*!dtor),/cont,linestyle=2,$
         thick=3,color='BLK5'
   
   ;; Make x,y position for plotting
   x = -duse[*,0] * sin(emaf.l*!dtor)
   y = -R0/1.d3 + duse[*,0] * cos(emaf.l*!dtor)
   FOR kk = 0L, n-1 DO $
      cgPlots,x[kk],y[kk],color=color[kk],psym=9,symsize=symsize[kk]
   
   ;; Sun and Galactic Center
   cgPlots,0,0,psym=7,color='BLK5',symsize=1.2,thick=8
   cgPlots,0,-R0/1.d3,psym=7,color='BLK5',symsize=1.2,thick=8
   cgText,0.1,0.4,'GC',charsize=0.7
   cgText,0.1,-8.1,'Sun',charsize=0.7
   
   cgColorbar,/vert,/right,charsize=0.8,divis=0,range=[0,0.5],$
              title='Contrast',position=[0.88,!Y.window[0],0.91,!Y.window[1]]


   cgText,-5.0,1.9,'Sagittarius Arm?',charsize=0.7,$
          alignment=0.5,orientation=60.,color='Red'
   ;; cgText,-5.0,3.3,'Perseus Arm?',charsize=0.7,$
   ;;        alignment=0.5,orientation=30.,color='Red'
   ;; cgText,-7.5,5.5,'Outer Arm?',charsize=0.7,$
   ;;        alignment=0.5,orientation=30.,color='Red'
   cgText,-1.0,-3.0,'End of Bar?',charsize=0.7,$
          alignment=0.5,orientation=0.,color='Red'
   cgText,+1.0,-5.5,'Sct-Cen Arm?',charsize=0.7,$
          alignment=0.5,orientation=0.,color='Red'

   
myps,/done
END

